Repository navigation
Feature/hw09 state machine, ballistic table, smart pointers - #9
Conversation
…nd std::array. fix loops. change char arrays to std::string
…ate classes in mission_processor step. remove redundant functions from simulation.cpp
…hods, use this for properties
…olver. change ammo params in json file. add ballistic_table.txt
… and path to ballistic table as arguments of the app. refactoring
…github.com/alex-popkov/rd_cpp_docker into feature/hw09-state-machine-ballistic-table # Conflicts: # drone_simulation/src/mission_processor.cpp
farnblack
left a comment
There was a problem hiding this comment.
ДЗ9 — код-рев'ю
src/mission_processor.cpp (весь step/evaluateTarget/getSimulationStep) — (ДЗ9-deliverable: TableSolver не працює)
// init():
this->ammoFlightTime = getAmmoFlightTime(this->droneConfig, this->ammo);
this->ammoHorizontalFlightDistance = getAmmoHorizontalFlightDistance(this->droneConfig.attackSpeed, this->ammoFlightTime, this->ammo);
// step()/evaluateTarget()/getSimulationStep() далі користуються лише цими двома полями.
// this->ballisticSolver НЕ викликається ніде, окрім конструктора і changeSolver().TableSolver::solve() реалізований правильно (справжня 5D-інтерполяція у BallisticTable::lookup), але жодного разу не викликається. Балістику в симуляції рахують вільні функції getAmmoFlightTime / getAmmoHorizontalFlightDistance (аналітичні формули Кардано з simulation.cpp), а об'єкт ballisticSolver лише зберігається в полі та ніде не використовується. Перевірив прогоном: запуск з аргументом analytical і з аргументом table дає побайтово однаковий simulation.json — солвер мертвий, перемикач не впливає ні на що. Головне завдання ДЗ9 (підключити табличний солвер у симуляцію) не виконане.
src/mission_processor.cpp + include/interfaces/ballistic_solver.hpp — (DIP / абстракція декоративна)
// MissionProcessor зберігає std::unique_ptr<IBallisticSolver> ballisticSolver,
// але вся балістика йде повз інтерфейс — через глобальні вільні функції.Оскільки балістика йде повз солвер, інтерфейс IBallisticSolver і фабрика солверів існують лише формально. Поліморфізм не задіяний — фабрика створює об'єкт, який нікуди не приєднаний. Балістику слід рахувати через ballisticSolver->solve(...), а не дублювати у вільних функціях.
src/main.cpp:41-46 — (немає перевірки на nullptr)
auto ballisticSolver = createSolver(solverType, droneConfig, ballisticTablePath);
// ... createSolver / createProvider / createLoader можуть повернути nullptr,
MissionProcessor missionProcessor(std::move(targets), std::move(ballisticSolver));
missionProcessor.init(std::move(loader));Усі три фабричні функції (factory.cpp) повертають nullptr для невідомого типу, але результат не перевіряється. Звертання до nullptr-компонента = UB. Перед використанням перевіряти кожен.
src/simulation.cpp:10 (#define ENABLE_LOG 1) + src/main.cpp:13 — (дебаг-вивід лишився ввімкненим)
#define ENABLE_LOG 1
// ... LOG(...) друкує у stdout, у т.ч. "No valid target at this step, skipping" та "Drone hit the target..."Логування лишилось увімкненим у фінальній здачі — симуляція засмічує stdout. Для здачі вимкнути.
Extracted evaluateTarget() and getSimulationStep() private methods from MissionProcessor::step()
Removed DroneMotion struct, inlined its fields into SimulationStep with drone prefix (droneSpeed, droneDirection, dronePosition, droneState)
Reordered SimulationStep fields for better memory alignment
Introduced DroneContext struct with const DroneConfig* pointer for shared state between state classes
Moved variable declarations inside try block in main.cpp (no manual cleanup needed with RAII)
Added CLI argument for solver type selection (analytical / table) and ballistic table path
Updated ammo parameters in ammo.json (VOG-17, M67, RKG-3, GLIDING-VOG, GLIDING-RKG)